<#import "/META-INF/spring.ftl" as spring />
<#include "../inc/header.ftl" />
	<script type="text/javascript" src="${base}/script/kindeditor/kindeditor.js" charset="utf-8"></script>
	<script type="text/javascript" src="${base}/script/jquery.form.js" charset="utf-8"></script>
	<script type="text/javascript" src="${base}/script/autocomplete.js" charset="utf-8"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			mlog.editor.init({
				model : "all",
				id : "content"
			});
			mlog.editor.init({
				model : "simple",
				id : "summary"
			});
		});
		
		//自动保存	
		function autosave(callback){
			$('#postForm').ajaxSubmit({
				url : '${base}/admin/post/autosave',
				success: function(responseText, statusText, xhr, $form){
					$("#id").val(responseText);
					if(callback !== undefined){
						callback(responseText, statusText);
					}
				}
			});
			setTimeout("autosave()", 60000);
		}
		autosave();
		function displayToggle(){
			autosave(function(responseText, statusText){
				$('#attach_frame').attr('src', '${base}/common/attachment/uploadview?fkey=' + responseText + '&ftype=POST');
				$('#attachment').fadeToggle();
			});
		}
		
		function addAttachFile(path,name){
			if (mlog.editor.map['content'].designMode === false){
				alert('请先切换到所见所得模式');
			} else {
				mlog.editor.map['content'].insertHtml('<span class=\"attachment\"><a target=\"_blank\" href=\"'+path+'\" >'+name+'</a></span>');
			}
		}
		
		function addAttachImage(path,id){
			if (mlog.editor.map['content'].designMode === false){
				alert('请先切换到所见所得模式');
			}else if (path != "") {
				mlog.editor.map['content'].insertHtml('<a target=\"_blank\" href=\"'+path+'\" id=\"ematt:'+id+'\"><img src=\"'+path+'\" title="点击查看原图" border=\"0\" /></a>');
			}
		}
	</script>
	<div id="error" class="message error" style="display:none;"></div>
	<form id="postForm" name="postForm" action="${base}/admin/post/create/save" method="POST">
		<@spring.bind "post" />
		<@spring.formHiddenInput path="post.status" />
		<@spring.formHiddenInput path="post.id" />
		<table class="formtable">
			<tr>
				<td class="fieldlabel" style="width:60px;">标题</td>
				<td colspan="3">
					<@spring.formInput path="post.title" attributes='class="textinput" style="width:99%;" validate=\'{required:true, messages:{required:"请输入文章标题"}}\'' />
				</td>
			</tr>
			<tr>
				<td class="fieldlabel" style="width:60px;">分类</td>
				<td>
					<@spring.formSingleSelect path="post.catalog.id" options=catalogs has_default=true attributes='validate=\'{required:true, messages:{required:"请选择文章分类"}}\' style="width:99%"'/>
				</td>
				<td class="fieldlabel">访问密码</td>
				<td>
					<@spring.formInput path="post.password" attributes='class="textinput" style="width:98%;"' />
				</td>
			</tr>
			<tr>
				<td class="fieldlabel">来源站点</td>
				<td>
					<@spring.formInput path="post.sourceSite" attributes='class="textinput" style="width:98%;"' />
				</td>
				<td class="fieldlabel">来源链接</td>
				<td>
					<@spring.formInput path="post.sourceUrl" attributes='class="textinput" style="width:98%;"' />
				</td>
			</tr>
			<tr>
				<td class="fieldlabel">允许评论</td>
				<td>
				<@spring.formRadioButtons path="post.commentStatus" options=commentStatus defaultValue="open" separator="&nbsp;" />
				</td>
				<td class="fieldlabel">是否置顶</td>
				<td>
				<@spring.formRadioButtons path="post.isTop" options=isTop defaultValue="false" separator="&nbsp;" />
				</td>
			</tr>
			<tr id="attachment" style="display: none;">
				<td colspan="4">
					<iframe id="attach_frame" width="100%" height="230" frameborder="0"></iframe>
				</td>
			</tr>
			<tr>
				<td class="fieldlabel">
					内容<br/>
					<a href="javascript:displayToggle();" style="font-weight: bold; color:red;">插入附件</a><br/>
				</td>
				<td colspan="3">
					<@spring.formTextarea path="post.content" attributes='style="height:200px;width:100%;"' />
				</td>
			</tr>
			<tr>
				<td class="fieldlabel">摘要</td>
				<td colspan="3">
					<@spring.formTextarea path="post.summary" attributes='style="height:150px;width:100%;"' />
				</td>
			</tr>
			<tr>
				<td colspan="4" style="text-align:center;">
					<input type="button" class="btn" value=" 发布内容 " onclick="publish();" />
					<input type="button" class="btn" value=" 保存为草稿 " onclick="draft();" />
				</td>
			</tr>
		</table>
	</form>
	<script type="text/javascript">
		//发布
		function publish(){
			$("#status").val("publish");
			if($("#postForm").valid()){
				mlog.form.submitForm("postForm");
			}
		}
		//存为草稿
		function draft(){
			$("#status").val("draft");
			mlog.form.submitForm("postForm");
		}
		
		$(document).ready(function(){
			//斑马线
			var tables=document.getElementsByTagName("table");
			var b=false;
			for (var j = 0; j < tables.length; j++){
				var cells = tables[j].getElementsByTagName("tr");
				//cells[0].className="color3";
				b=false;
				for (var i = 0; i < cells.length; i++){
					if(b){
						cells[i].className="color2";
						b=false;
					}
					else{
						cells[i].className="color3";
						b=true;
					};
				};
			}
			
			mlog.form.validate({
				selector : "#postForm",
				errorLabelContainer : "#error",
				wrapper: 'li',
				onfocusout : false,
				onkeyup : false,
				onclick : false,
				success : function(){
					mlog.utils.scrollTop();
				}
			});
			
		});
	</script>
<#include "../inc/footer.ftl" />